﻿
namespace SomethingSpacialClassLib.Web
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.ServiceModel.DomainServices.Server;
    using System.ServiceModel.DomainServices.EntityFramework;


    // Implements application logic using the SUGWTKEntities1 context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    // [RequiresAuthentication]
    public partial class SomethingSpacialService : LinqToEntitiesDomainService<SUGWTKEntities1>
    {

        public IQueryable<EventFeedback> GetEventFeedbacksNext(int EventFeedbackID)
        {
            return this.ObjectContext.EventFeedbacks.Where(e => e.EFB_ID > EventFeedbackID).OrderBy(e => e.EFB_ID).Take(1);
        }
        public IQueryable<EventFeedback> GetEventFeedbacksLatest(int EventID)
        {
            return this.ObjectContext.EventFeedbacks.Where(e => e.EFB_EventID == EventID).OrderByDescending(e => e.EFB_ID).Take(1);
        }

        //JL: Added this to get All the Latest Feedbacks from an Event
        public IQueryable<EventFeedback> GetAllEventFeedbacks(int EventID)
        {
            //var EventFeedBacks = this.ObjectContext.EventFeedbacks;
            var EventFeedBacks = this.ObjectContext.EventFeedbacks.Where(e => e.EFB_EventID == EventID).OrderByDescending(e => e.EFB_ID);

            return EventFeedBacks;
        }

        //We get the latest Feedbacks from a concrete feedback
        public IQueryable<EventFeedback> GetAllEventFeedbacksFromId(int EventID, int Id)
        {
            var LatestEventFeedbacks = from ef in this.ObjectContext.EventFeedbacks
                                       where (ef.EFB_EventID == EventID &&
                                              ef.EFB_ID > Id)
                                       orderby ef.EFB_ID
                                       select ef;

            return LatestEventFeedbacks;
        }

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<EventFeedback> GetEventFeedbacks()
        {
            return this.ObjectContext.EventFeedbacks;
        }

        public void InsertEventFeedback(EventFeedback eventFeedback)
        {
            
                if ((eventFeedback.EntityState != EntityState.Detached))
                {
                    this.ObjectContext.ObjectStateManager.ChangeObjectState(eventFeedback, EntityState.Added);
                }
                else
                {
                    this.ObjectContext.EventFeedbacks.AddObject(eventFeedback);
                }
            
        }


        public void UpdateEventFeedback(EventFeedback currentEventFeedback)
        {
                this.ObjectContext.EventFeedbacks.AttachAsModified(currentEventFeedback, this.ChangeSet.GetOriginal(currentEventFeedback));
         
        }

        public void DeleteEventFeedback(EventFeedback eventFeedback)
        {
            if ((eventFeedback.EntityState == EntityState.Detached))
            {
                this.ObjectContext.EventFeedbacks.Attach(eventFeedback);
            }
            this.ObjectContext.EventFeedbacks.DeleteObject(eventFeedback);
        }





    }
}


